//dp[i]：代表从i位置出发到楼顶的最小花费
class Solution {
    public int minCostClimbingStairs(int[] cost) {

        //1.创建dp表
        //2.初始化
        //3.根据状态转移方程填表
        //4.返回值
        int n = cost.length;
        int[] dp = new int [n+1];
        dp[n-1] = cost[n-1];
        dp[n-2] = cost[n-2];
        for(int i=n-2;i>=0;i--) {
            dp[i] = Math.min(dp[i+1]+cost[i],dp[i+2]+cost[i]);
        }
        return Math.min(dp[1],dp[0]);
    }
}
